package com.wzy.echarts.controller;

import com.wzy.common.core.controller.BaseController;

import com.wzy.sxcg.domain.ScoreStat;
import com.wzy.sxcg.mapper.SxcgSxcjMapper;
import com.wzy.system.domain.DeptEcharts;
import com.wzy.system.mapper.SysDeptMapper;
import com.wzy.xxgl.mapper.XxglXsxxMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * EchartsController
 * 
 * @author wzy
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/echarts")
public class EchartsController extends BaseController
{
    @Autowired
    private XxglXsxxMapper xxglXsxxMapper;

    @Autowired
    private SxcgSxcjMapper sxcgSxcjMapper;

    @Autowired
    private SysDeptMapper deptMapper;
    /**
     * 查询实习成绩列表
     */
    @GetMapping("/data")
    public Map<String, Object> list()
    {
        Map<String,Object> map = new HashMap<>();
        Integer xszrs= xxglXsxxMapper.selectCount(null);
        Integer sxjxz = xxglXsxxMapper.selectCount("jxz");
        Integer sxyjs = xxglXsxxMapper.selectCount("yjs");
        Integer sxwks = xszrs-sxjxz-sxyjs;
        map.put("xszrs",xszrs);
        map.put("sxwks",sxwks);
        map.put("sxjxz",sxjxz);
        map.put("sxyjs",sxyjs);

        /*学院列表查询*/
        List<DeptEcharts> deptEchartsList = deptMapper.selectEchartsDeptData();
        List<String> deptNameListTemp = new ArrayList<>();
        List<Integer> deptStudentCountListTemp = new ArrayList<>();

        for (DeptEcharts item : deptEchartsList) {
            deptNameListTemp.add(item.getDeptName());
            deptStudentCountListTemp.add(item.getStudentCount());
        }
        // 转换为数组
        String[] deptNameList = deptNameListTemp.toArray(new String[0]);
        Integer[] deptStudentCountList = deptStudentCountListTemp.toArray(new Integer[0]);

        map.put("deptNameList",deptNameList);
        map.put("deptStudentCountList",deptStudentCountList);

        ScoreStat  scoreStat = sxcgSxcjMapper.selectSxcjStat();
        Integer excellentCount = scoreStat.getExcellentCount() == null ? 0 : scoreStat.getExcellentCount();
        Integer goodCount = scoreStat.getGoodCount() == null ? 0 : scoreStat.getGoodCount();
        Integer badCount = scoreStat.getBadCount() == null ? 0 : scoreStat.getBadCount();

        map.put("excellentCount",excellentCount);
        map.put("goodCount",goodCount);
        map.put("badCount",badCount);
        return map;
    }

}
